<template>
  <div class="search-container">
      <div class="search-bar">
        <input
          v-model="query"
          type="text"
          placeholder="请输入搜索关键词..."
          @keyup.enter="search"
          clearable
      prefix-icon="el-icon-search"
        />
        <button class="search-button"  @click="search">
          <i class="el-icon-search"></i> 搜索
        </button>
      </div>
    </div>

</template>

<script>

export default {
 
  data() {
    return {
      query: '',
    };
  },
  created() {
    // 从查询参数中获取搜索关键词
    this.query = this.$route.query.keyword || '';
  },
  methods: {
    search() {
      this.$emit('search', this.query);
    },
  },
};
</script>

<style scoped>
.search-container {
  display: flex;
  justify-content: center;
  align-items: center;
  height: 100vh;
  background-color: #f7f7f7;
}

/* 搜索框及按钮样式 */


.search-bar {
  display: flex;
  align-items: center;
  background-color: #f7f7f7;
  border-radius: 20px;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.1);
  padding: 0 12px;
  transition: all 0.3s ease;
  z-index: 1; /* 提高搜索框的层级 */
}

.search-bar:hover {
  transform: scale(1.02);
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.15);
}

.search-bar input {
  flex-grow: 1;
  height: 44px;
  font-size: 16px;
  color: #666;
  background-color: transparent;
  border: none;
  outline: none;
  padding-left: 12px;
  z-index: 2; /* 提高输入框的层级 */
}

.search-bar input::placeholder {
  color: #666;
}

.search-button {
  background-color: #f3a14f;
  color: #f7f7f7;
  border: none;
  border-radius: 20px;
  height: 36px;
  padding: 0 18px;
  font-size: 14px;
  display: flex;
  justify-content: center;
  align-items: center;
  cursor: pointer;
  transition: all 0.3s ease;
  z-index: 2; /* 提高按钮的层级 */
}

.search-button:hover {
  background-color: #f3a14f;
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(109, 76, 65, 0.3);
  animation: pulse 0.8s infinite;
}

.search-bar:focus-within {
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

@keyframes pulse {
  0% {
    transform: scale(1);
  }
  50% {
    transform: scale(1.05);
  }
  100% {
    transform: scale(1);
  }
}
</style>